package core;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import towers.Bunker;
import towers.Cannon;
import towers.MissileLauncher;
import towers.NuclearBase;
import towers.Plasmagun;

/**
 * @author Arno de Jager
 * @version 1.1
 * @since 2011-04-11
 */
public class Controller implements ActionListener {

	private View view;
	private Model model;
	private Mouse mouse;

	/**
	 * @param m het model
	 */
	/* /// Constructor //////////////////////////////////////// */
	public Controller(Model m) {
		this.mouse = new Mouse(m);

		view = new View(m, this);
		this.model = m;

		model.addObserver(view);
	}
	
	/* /// getView //////////////////////////////////////// */
	public View getView() {
		return this.view;
	}

	/* /// actionPerformed //////////////////////////////////////// */
	public void actionPerformed(ActionEvent e) {
		// Bouw torens
		if (e.getActionCommand().equals("Cannon")) {
			this.mouse.setSelectedItem(new Cannon(null));
		} else if (e.getActionCommand().equals("Bunker")) {
			this.mouse.setSelectedItem(new Bunker(null));
		} else if (e.getActionCommand().equals("Missile Launcher")) {
			this.mouse.setSelectedItem(new MissileLauncher(null));
		} else if (e.getActionCommand().equals("Nuclear Base")) {
			this.mouse.setSelectedItem(new NuclearBase(null));
		} else if (e.getActionCommand().equals("Plasmagun")) {
			this.mouse.setSelectedItem(new Plasmagun(null));
		}

		// Etcetera
		else if (e.getActionCommand().equals("Next Wave")) {
			model.nextWave();
		} else if (e.getActionCommand().equals("Repair")) {
			model.repair(this.mouse.getSelectedItem());
		} else if (e.getActionCommand().equals("Sell")) {
			model.sell(this.mouse.getSelectedItem());
		} else if (e.getActionCommand().equals("Pause")) {
			model.togglePause();
		}
	}

	/* /// getMouse //////////////////////////////////////// */
	public Mouse getMouse() {
		return mouse;
	}
}